package com.session1;


import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class JFrameDemo extends JFrame implements ItemListener{
	private JCheckBox chItem = null;
	private JTextField txtResult;
	private JPanel p1 = null;
//	public JFrameDemo(){
//		
//	}
	public static void main(String[] args) {
		JFrameDemo d = new JFrameDemo();
		d.createForm();
		d.showForm();
	}
	public void createForm(){
		//Khoi tao cac control
		this.p1 = new JPanel();
		this.chItem = new JCheckBox();
		this.txtResult = new JTextField(20);
		// dang ki su kien
		this.chItem.addItemListener(this);
		// dua control vao container
		this.p1.add(this.chItem);
		this.p1.add(this.txtResult);
		this.getContentPane().add(p1);
	}
	public void showForm(){
		this.setTitle("Demo JFram");
		this.setSize(400,300);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setVisible(true);
	}
	@Override
	public void itemStateChanged(ItemEvent e) {
		if(e.getSource() == this.chItem){
			this.txtResult.setText(this.chItem.isSelected()+"");
		}
	}
}
